//
// Created by Administrator on 2024/1/31.
//
#include <vector>
#include <iostream>
#include <math.h>
using namespace std;

class Solution
{
public:
    int findClosestNumber(vector<int>& nums)
    {
        // 请你返回 nums 中最 接近 0 的数字
        int ans = nums[0];
        for (int i = 1; i < nums.size(); i++)
        {
            if (abs(nums[i]) < abs(ans))
            {
                ans = nums[i];
            }
            else if (abs(nums[i]) == abs(ans))
            {
                ans = max(ans, nums[i]);
            }
        }
        return ans;
    }
};

int main()
{
    vector<int> nums{2,-1,1};
    Solution s;
    cout << s.findClosestNumber(nums) << endl;
}
